;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2022 jgart <jgart@dismail.de>
;;; Copyright © 2022 Attila Lendvai <attila@lendvai.name>
;;; Copyright © 2022 florhizome <florhizome@posteo.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages common guile)
  #:use-module (guix build-system guile)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system cargo)
  #:use-module (guix git-download)
  #:use-module (guix hg-download)
  #:use-module (guix download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages guile-xyz)
  #:use-module (gnu packages crates-io)
  #:use-module (gnu packages package-management))

(define-public guile-for-loops
  (let ((commit "580d3fb365ea2734b037ad3ca7f2ab1e4aa5116d") (revision "0"))
    (package
      (name "guile-for-loops")
      (version (git-version "0.0.0" revision commit))
      (source (origin
                (method hg-fetch)
                (uri (hg-reference (url
                                    "https://hg.sr.ht/~bjoli/guile-for-loops")
                                   (changeset commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0ksz08v2msdd0xsvjvyg05ka9frphcgvy4vh4ax516bgg9sra9r1"))))
      (inputs (list guix))
      (native-inputs (list guile-3.0))
      (build-system guile-build-system)
      (home-page "https://hg.sr.ht/~bjoli/guile-for-loops")
      (synopsis "Efficient looping facility for guile")
      (description
       "@code{guile-for-loops} is a re-implementation of a large-ish chunk of
racket for-macros.  @code{guile-for-loops} is mostly compatible with
racket's macros, with the largest omission being the body-or-break
clause and some of the sequence iterators (like in-cycle, which can
be covered by circular lists).  There are other differences of course,
like for/foldr not being on par feature-wise, and all the nicities you
get by having a generic sequence interface.")
      (license license:mpl2.0))))

(define-public guile-threading-macros
  (let ((commit "a438588baf9d06b0bc47167b2f670b8c651482ec") (revision "0"))
    (package
      (name "guile-threading-macros")
      (version (git-version "0.0.0" revision commit))
      (source (origin
                (method hg-fetch)
                (uri (hg-reference (url
                                    "https://hg.sr.ht/~bjoli/guile-threading-macros")
                                   (changeset commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0mxlvlj1cbsqsr7d43hk8shlnzb3mklvgdfzygyq68bjl700af3a"))))
      (inputs (list guix))
      (native-inputs (list guile-3.0))
      (build-system guile-build-system)
      (home-page "https://hg.sr.ht/~bjoli/guile-threading-macros")
      (synopsis "Threading macros for guile scheme")
      (description
       "@code{guile-threading-macros} implements a version of the famous clojure
threading macros.  These are syntax-rules macros, and are as such portable
across r(5 6 7)rs-conforming implementations.")
      (license license:bsd-3))))

(define-public guile-srfi-189
  (let ((commit "a0e3786702956c9e510d92746474ac988c2010ec")
        (revision "0"))
    (package
      (name "guile-srfi-189")
      (version (git-version "0" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               ;; This is a fork of:
               ;; (url "https://github.com/scheme-requests-for-implementation/srfi-189")
               ;; Upstream merge requested at:
               ;; https://github.com/scheme-requests-for-implementation/srfi-189/pull/21
               ;; TODO switch over to the official repo when the PR gets merged
               (url "https://github.com/attila-lendvai-patches/srfi-189")
               (commit commit)))
         (sha256
          (base32
           "0iqv4sjwbp4k87r9l9abzbs5yjcljm69m91kb1ypb03b0rx7napy"))
         (modules '((guix build utils)))
         (snippet
          '(begin
             (delete-file "test-syntax.scm")
             (delete-file "test.scm")))
         (file-name (git-file-name name version))))
      (build-system guile-build-system)
      (arguments
       '(#:not-compiled-file-regexp "srfi/189\\.scm$")) ; it's INCLUDE'd
      (native-inputs
       (list guile-3.0))
      (propagated-inputs
       (list guile-srfi-145))
      (home-page "https://srfi.schemers.org/srfi-189/")
      (synopsis "Scheme SRFI implementation of Maybe and Either")
      (description
       "This SRFI defines two disjoint immutable container types known as
Maybe and Either, both of which can contain objects collectively known
as their payload.  A Maybe object is either a Just object or the unique
object Nothing (which has no payload); an Either object is either a Right
object or a Left object.  Maybe represents the concept of optional values;
Either represents the concept of values which are either correct (Right)
or errors (Left).")
      (license license:expat))))
